export interface ShowModalInterface {
  title?: string
  content: string
  options?: any
  successCallback?(arg0?: any, arg1?: any): Promise<any> //回调函数
  cancelCallback?(arg0?: any, arg1?: any): Promise<any> //回调函数
}
export default function useToastMsg() {
  const showLoading = (title = '加载中') => uni.showLoading({ title: title, mask: true })

  const hideLoading = () => uni.hideLoading()

  const showToast = (title: string, options = {}) => uni.showToast({ title: title, duration: 3000, icon: 'none', ...options })

  const successMsg = (title: string, options = {}) => uni.showToast({ title: title, duration: 3000, icon: 'success', ...options })

  const errorMsg = (title: string, options = {}) => uni.showToast({ title: title, duration: 3000, icon: 'error', ...options })

  const closeMsg = () => uni.hideToast()

  const showModalMsg = (data: ShowModalInterface) => {
    let params: any = data.options ? { ...data.options } : {}
    params.title = data.title || '提示'
    params.content = data.content
    uni.showModal({
      ...params,
      success: (res: any) => {
        if (res.confirm) {
          data.successCallback && data.successCallback(res)
        } else if (res.cancel) {
          data.cancelCallback && data.cancelCallback(res)
        }
      },
    })
  }

  return {
    showToast,
    successMsg,
    errorMsg,
    closeMsg,
    showLoading,
    hideLoading,
    showModalMsg,
  }
}
